#include <iostream>
#include <string>
#include <map>
#include <vector>

/*
    1. nums1,num2需要判断是奇偶数
    2. nums1,num2一共多少个数，然后中值是在那个位置，是单个数，还是两个数的均值，这个应该作为target索引
    3.

*/

class Solution
{
public:
    double findMedianSortedArrays(std::vector<int> &nums1, std::vector<int> &nums2)
    {
        int n1 = nums1.size();
        int n2 = nums2.size();
        int n = n1 + n2;
        int target = (n + 1) / 2;
        int current = 0;
        int mid = 0;
        int idx1 = 0;
        int idx2 = 0;
        while (current < target && current < n1 && current < n2)
        {
            if (nums1[idx1] < nums2[idx2])
            {
                mid = nums1[idx1++];
            }
            else
            {
                mid = nums2[idx2++];
            }
            current++;
        }

        if (current == target)
        {
            return (double)(mid + (n1 + n2 - 2 * target) * (nums1[idx1] < nums2[idx2] ? 1 : -1)) / 2;
        }
        else if (current < target)
        {
            if (current == n1)
            {
                return (double)nums2[idx2 + target - current] / 2;
            }
            else
            {
                return (double)nums1[idx1 + target - current] / 2;
            }
        }
        else
        {
            return (double)mid / 2;
        }
    }
};

int main(int argc, char **argv)
{
    std::vector<int> num1 = {1, 2, 3, 4, 5, 6, 10, 90};
    std::vector<int> num2 = {3, 6, 10, 35};
    std::cout << Solution().findMedianSortedArrays(num1, num2)
              << std::endl;   

    return 0;
}
